//
//  HLTmerchanthomeTableViewController.m
//  huiliantong
//
//  Created by hlt on 15/9/28.
//  Copyright © 2015年 hlt. All rights reserved.
//

#import "HLTmerchanthomeTableViewController.h"
//#import "NetworkSingleton.h"
#import "AppDelegate.h"
#import "HLTShopViewController.h"
#import "MJExtension.h"
//#import "JZMerchantModel.h"
//#import "JZMerchantCell.h"
#import "MJRefresh.h"
#import "RecommendCell.h"
#import "SearchViewController.h"
#import "cloudsearchmapViewController.h"
#import "JSDropDownMenu.h"
#import "SliderViewController.h"
#import "HLTzhoubiantuijianyouhuimerchantTableViewController.h"
#import <BaiduMapAPI/BMapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface HLTmerchanthomeTableViewController ()<BMKMapViewDelegate, BMKCloudSearchDelegate,BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate,UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate,CLLocationManagerDelegate,JSDropDownMenuDataSource,JSDropDownMenuDelegate>
{
    
    NSMutableArray *data1;
    
    NSMutableArray *_data2;
    
    NSMutableArray *_data3;
    
    NSArray *typelist;
    
    
    
    NSInteger _currentData1Index;
    
    NSInteger _currentData2Index;
    
    NSInteger _currentData3Index;
    
    NSMutableArray *_recommendArray;
    NSMutableArray *_MerchantArray;
    NSString *_locationInfoStr;
    NSInteger _KindID;//分类查询ID，默认-1
    NSInteger _offset;
    UIView *_maskView;
    BMKGeoCodeSearch *searcher;//位置反编译的工具
    
    __weak IBOutlet BMKMapView *_mapView;
    BMKCloudSearch* _search;
    
    //    JZMerchantFilterView *_groupView;
}
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (strong, nonatomic) BMKLocationService *locService ;
@property (strong, nonatomic) CLLocation *location;
@property (strong, nonatomic) NSString *lat;
@property (strong, nonatomic) NSString *log;
@property (strong, nonatomic) NSString *haiba;



@end

@implementation HLTmerchanthomeTableViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    self.navigationController.navigationBarHidden = YES;
//    self.view.backgroundColor = [UIColor whiteColor];
    //设置默认获取的商铺分类
    self.shoptype=@"全部类型";
    self.shoparea=@"";
    [self initData];
//    [self setNav];
    [self initViews];
    [self initMaskView];
    [self createLocationManager];
}




//创建位置管理器及其相关操作
- (void) createLocationManager
{
    
    //1.创建位置管理器
    self.locationManager = [[CLLocationManager alloc] init];
    //指定委托
    self.locationManager.delegate = self;
    //指定所需精度
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    //距离筛选器
    self.locationManager.distanceFilter = 10;
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        [self.locationManager requestAlwaysAuthorization];
    }
    
    //启动
    [self.locationManager startUpdatingLocation];
    
    //
    //设置定位精确度，默认：kCLLocationAccuracyBest
    [BMKLocationService setLocationDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
    //指定最小距离更新(米)，默认：kCLDistanceFilterNone
    [BMKLocationService setLocationDistanceFilter:100.f];
    
    //初始化BMKLocationService
    _locService = [[BMKLocationService alloc]init];
    _locService.delegate = self;
    [_locService startUserLocationService];
    
    
    
}



////处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    
    //    CLLocation *newLocation = locations[0];
    //    CLLocationCoordinate2D oldCoordinate = newLocation.coordinate;
    //    NSLog(@"旧的经度：%f,旧的纬度：%f",oldCoordinate.longitude,oldCoordinate.latitude);
    //
    //    //    CLLocation *newLocation = locations[1];
    //    //    CLLocationCoordinate2D newCoordinate = newLocation.coordinate;
    //    //    NSLog(@"经度：%f,纬度：%f",newCoordinate.longitude,newCoordinate.latitude);
    //
    //    // 计算两个坐标距离
    //    //    float distance = [newLocation distanceFromLocation:oldLocation];
    //    //    NSLog(@"%f",distance);
    
    
    
    
    
    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    
    self.lat=  [NSString stringWithFormat:@"%g",  userLocation.location.coordinate.latitude];
    self.log =  [NSString stringWithFormat:@"%g",  userLocation.location.coordinate.longitude];
    //海拔
    self.haiba = [NSString stringWithFormat:@"%g", userLocation.location.verticalAccuracy];
    self.location =userLocation.location;
    
    CLLocationCoordinate2D pt = (CLLocationCoordinate2D){userLocation.location.coordinate.latitude,  userLocation.location.coordinate.longitude};
    
    
    
    //反编译位置坐标得到街道信息
    searcher =[[BMKGeoCodeSearch alloc]init];
    searcher.delegate = self;   //委托的方法是onGetReverseGeoCodeResult
    
    
    BMKReverseGeoCodeOption *reverseGeoCodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
    reverseGeoCodeSearchOption.reverseGeoPoint = pt;
    BOOL flag = [searcher reverseGeoCode:reverseGeoCodeSearchOption];
    
    if(flag)
    {
        NSLog(@"*****eo检索发送成功");
    }
    else
    {
        NSLog(@"*****eo检索发送失败");
    }
    
    //达到100米的位置误差后再次调用周边
    //    [self onClickNearbySearch];
    
    
}
//定位失败调用
- (void)didFailToLocateUserWithError:(NSError *)error
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"定位失败，请检查是否有定位权限!" message:[NSString stringWithFormat:@"%@", error] delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil, nil];
    [alert show];
    
}


//接收反向地理编码结果
-(void) onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{
    
    
    _locationInfoStr=result.address;
    
    //        NSUserDefaults *userD = [NSUserDefaults standardUserDefaults];
    //        [userD setObject:_locationInfoStr forKey:@"location"];
    //
    [self.tableView reloadData];
    
    [_locService stopUserLocationService];
    NSLog(@"%@",result.address);
    
    
}


-(void) getcategary
{
    
    data1= [NSMutableArray arrayWithCapacity:5];
    
    //    NSString *url=[shopcategory stringByAppendingFormat:@"&page=%ld",(long)page1];
    NSString *url=shopcategory;
    [HLTNetWorkingtool getary:url success:^(NSArray *ary) {
        
        
        //获取类型数组
        typelist=ary;
        
        //                                           typelist=dicc[@"List_Item"];
        
        NSMutableArray *type123= [NSMutableArray arrayWithCapacity:5];
        [type123 addObject:@"全部类型"];
        
        //添加全部分类的菜单到第一个
        NSDictionary *menutypedic=[NSDictionary dictionaryWithObjectsAndKeys:@"全部类型",@"title",type123,@"data",nil];
        [data1 addObject:menutypedic];
        for (id parintvalue in typelist) {
            NSMutableArray *food= [NSMutableArray arrayWithCapacity:5];
            for (id value in [parintvalue objectForKey: @"code"]) {
                
                NSLog(@"%@",value[@"shop_class_name"]);
                
                [food addObject:value[@"shop_class_name"]];
                
            }
            
            
            
            [food insertObject:[@"全部" stringByAppendingString:parintvalue[@"parent"][@"shop_class_name"]] atIndex:0];
            
            
            
            NSDictionary *menutypedic=[NSDictionary dictionaryWithObjectsAndKeys:parintvalue[@"parent"][@"shop_class_name"],@"title",food,@"data",nil];
            
            
            
            [data1 addObject:menutypedic];
        }
        
        //        [data1 insertObject:@"全部分类" atIndex:0];
        
        //_data1 = [NSMutableArray arrayWithObjects:@{@"title":@"美食", @"data":food}, @{@"title":@"旅游", @"data":travel}, nil];
        _data2 = [NSMutableArray arrayWithObjects:@"贵阳",@"南明区",@"云岩区",@"贵安新区",@"花溪区",@"小河区",@"乌当区",@"白云区",@"金阳新区",@"开阳县",@"息烽县",@"修文县",@"清镇市",nil];
        
        _data3 = [NSMutableArray arrayWithObjects:@"不限人数",nil];
        
        
        
        
        JSDropDownMenu *menu =[[JSDropDownMenu alloc] initWithOrigin:CGPointMake(0, 0) andHeight:40];
        //        [[JSDropDownMenu alloc] initWithFrame:CGRectMake(0, 64, screen_width, 40)];
        
        menu.indicatorColor = [UIColor colorWithRed:195.0f/255.0f green:110.0f/255.0f blue:0.0f/255.0f alpha:1.0];
        
        menu.separatorColor = [UIColor colorWithRed:254.0f/255.0f green:250.0f/255.0f blue:193.0f/255.0f alpha:1.0];
        
        menu.textColor = [UIColor colorWithRed:195.0f/255.0f green:110.0f/255.0f blue:0.0f/255.0f alpha:1.0f];
        menu.dataSource = self;
        menu.delegate = self;
        //        UIView *filterView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, screen_width, 40)];
        //        filterView.backgroundColor = [UIColor whiteColor];
        
        [self.view addSubview:menu];
    } faliure:^(NSString *error) {
        
        
        
        
    }];
    
    
    
}








#pragma mark - menu的委托方法

- (NSInteger)numberOfColumnsInMenu:(JSDropDownMenu *)menu {
    
    
    
    return 2;
    
}



-(BOOL)displayByCollectionViewInColumn:(NSInteger)column{
    
    
    
    if (column==2) {
        
        
        
        return YES;
        
    }
    
    return NO;
    
}

-(BOOL)haveRightTableViewInColumn:(NSInteger)column{
    
    if (column==0) {
        
        return YES;
    }
    return NO;
}

-(CGFloat)widthRatioOfLeftColumn:(NSInteger)column{
    
    if (column==0) {
        return 0.3;
    }
    return 1;
}

//返回选择不同菜单，分类还是排序，得到的该目录下的选择的左边的第几个

-(NSInteger)currentLeftSelectedRow:(NSInteger)column{
    
    if (column==0) {
        
        NSLog(@"%ld",(long)_currentData1Index);
        
        return _currentData1Index;
        
    }
    
    if (column==1) {
        return _currentData2Index;
        
    }
    return 0;
    
}



- (NSInteger)menu:(JSDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow
{
    if (column==0) {
        
        if (leftOrRight==0) {
            return data1.count;
            
        } else{
            NSDictionary *menuDic = [data1 objectAtIndex:leftRow];
            
            return [[menuDic objectForKey:@"data"] count];
        }
        
    } else if (column==1){
        return _data2.count;
        
    } else if (column==2){
        return _data3.count;
        
    }
    return 0;
    
}



- (NSString *)menu:(JSDropDownMenu *)menu titleForColumn:(NSInteger)column{
    switch (column) {
            
        case 0: return [[data1[0] objectForKey:@"data"] objectAtIndex:0];
            
            break;
            
        case 1: return _data2[0];
            
            break;
            
        case 2: return _data3[0];
            
            break;
            
        default:
            
            return nil;
            
            break;
            
    }
    
}



- (NSString *)menu:(JSDropDownMenu *)menu titleForRowAtIndexPath:(JSIndexPath *)indexPath {
    
    
    
    if (indexPath.column==0) {
        
        if (indexPath.leftOrRight==0) {
            
            NSDictionary *menuDic = [data1 objectAtIndex:indexPath.row];
            
            return [menuDic objectForKey:@"title"];
            
        } else{
            
            NSInteger leftRow = indexPath.leftRow;
            
            NSDictionary *menuDic = [data1 objectAtIndex:leftRow];
            
            return [[menuDic objectForKey:@"data"] objectAtIndex:indexPath.row];
            
        }
        
    } else if (indexPath.column==1) {
        
        
        
        return _data2[indexPath.row];
        
        
        
    } else {
        
        
        
        return _data3[indexPath.row];
        
    }
    
}

//_currentData1Index记录了上一次的点击，在满足column的情况下,如果上一次点击过，_currentData1Index自动记录左边的菜单的选中项

- (void)menu:(JSDropDownMenu *)menu didSelectRowAtIndexPath:(JSIndexPath *)indexPath {
    
    if (indexPath.column == 0) {
        
        //leftOrRight为0时表示的是选择了左边的一级菜单，else为2级菜单
        
        if(indexPath.leftOrRight==0){
            
            _currentData1Index = indexPath.row;
            return;
            
        }else{
            
            
            //点击全部分类时的效果
            if (_currentData1Index==0) {
                
                
                self.shoptype=@"全部类型";
                //                _offset=0;
                //                [self getMerchantList];
            }
            else
            {
                //在没有点击全部分类时的事件
                NSString *typeid;
                
                if (indexPath.row==0) {
                    
                    self.shoptype= typelist[_currentData1Index-1][@"parent"][@"shop_class_name"];
                    typeid= typelist[_currentData1Index-1][@"parent"][@"cat_id"];
                    
                }else
                    
                {
                    
                    self.shoptype= typelist[_currentData1Index-1][@"code"][indexPath.row-1][@"shop_class_name"];
                    typeid= typelist[_currentData1Index-1][@"code"][indexPath.row-1][@"cat_id"];
                    
                }
                //在这里写点击事件
                //获取不同分类的商家
                _offset=0;
                [self getMerchantList];
                
            }
            
        }
    } else if(indexPath.column == 1){
        
        
        NSLog(@"%ld",(long)_currentData2Index);
        
        
        
        
        
        _currentData2Index = indexPath.row;
        if (indexPath.row==0) {
            self.shoparea=@"";
            
            //              typelist[_currentData1Index-1][@"parent"][@"cat_name"];
        }else
        {
            self.shoparea=_data2[indexPath.row];
            //              self.shoptype= typelist[_currentData1Index-1][@"code"][indexPath.row-1][@"cat_name"];
        }
        //在这里写点击事件
        //获取不同分类的商家
        _offset=0;
        [self getMerchantList];
        
        
        
        
        
        NSLog(@"%ld",(long)_currentData2Index);
        
    } else{
        
        NSLog(@"%ld",(long)_currentData3Index);
        _currentData3Index = indexPath.row;
        
        NSLog(@"%ld",(long)_currentData3Index);
        
    }
    
}











-(void)viewWillAppear:(BOOL)animated {
    
    
    //隐藏导航
    self.navigationController.navigationBarHidden=YES;
    
    
}

-(void)viewWillDisappear:(BOOL)animated {
    //停止定位LocationService
    [_locService stopUserLocationService];
    
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)initData{
    _MerchantArray = [[NSMutableArray alloc] init];
    _recommendArray = [[NSMutableArray alloc] init];   //商铺数据
    //    _locationInfoStr = @"正在定位...";
    NSUserDefaults *userD = [NSUserDefaults standardUserDefaults];
    _locationInfoStr = [userD objectForKey:@"location"];
    
    _offset = 0;
    _KindID = -1;//默认-1
}

-(void)initViews{
    //筛选
    
    [self getcategary];
    
    
    //tableview
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, screen_width, screen_height-40-49) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    [self setUpTableView];
}

//遮罩页
-(void)initMaskView{
    _maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 40, screen_width, screen_height-40-49)];
    //    _maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 64+40, screen_width, 0)];
    _maskView.backgroundColor = RGBA(0, 0, 0, 0.5);
    [self.view addSubview:_maskView];
    _maskView.hidden = YES;
    
    //添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapMaskView:)];
    tap.delegate = self;
    [_maskView addGestureRecognizer:tap];
    
    //
    //    _groupView = [[JZMerchantFilterView alloc] initWithFrame:CGRectMake(0, 0, screen_width, _maskView.frame.size.height-90)];
    //    _groupView.delegate = self;
    //    [_maskView addSubview:_groupView];
}

-(void)setUpTableView{
    //添加下拉的动画图片
    //设置下拉刷新回调
    [self.tableView addGifHeaderWithRefreshingTarget:self refreshingAction:@selector(getFirstPageData)];
    
    //设置普通状态的动画图片
    NSMutableArray *idleImages = [NSMutableArray array];
    for (NSUInteger i = 1; i<=60; ++i) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"dropdown_anim__000%zd",i]];
        [idleImages addObject:image];
    }
    [self.tableView.gifHeader setImages:idleImages forState:MJRefreshHeaderStateIdle];
    
    //设置即将刷新状态的动画图片
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSInteger i = 1; i<=3; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"dropdown_loading_0%zd",i]];
        [refreshingImages addObject:image];
    }
    [self.tableView.gifHeader setImages:refreshingImages forState:MJRefreshHeaderStatePulling];
    
    //设置正在刷新是的动画图片
    [self.tableView.gifHeader setImages:refreshingImages forState:MJRefreshHeaderStateRefreshing];
    
    //马上进入刷新状态
    [self.tableView.gifHeader beginRefreshing];
    
    
    //上拉刷新
    [self.tableView addGifFooterWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    
    //隐藏状态文字
    //    self.tableView.footer.stateHidden = YES;
    //设置正在刷新的动画
    self.tableView.gifFooter.refreshingImages = refreshingImages;
    
    
    
    
}




-(void)OnFilterBtn:(UIButton *)sender{
    for (int i = 0; i < 3; i++) {
        UIButton *btn = (UIButton *)[self.view viewWithTag:100+i];
        UIButton *sanjiaoBtn = (UIButton *)[self.view viewWithTag:120+i];
        btn.selected = NO;
        sanjiaoBtn.selected = NO;
    }
    sender.selected = YES;
    UIButton *sjBtn = (UIButton *)[self.view viewWithTag:sender.tag+20];
    sjBtn.selected = YES;
    _maskView.hidden = NO;
}

-(void)OnTapMaskView:(UITapGestureRecognizer *)sender{
    _maskView.hidden = YES;
}

#pragma mark - 请求数据

//获取当前位置信息
-(void)OnRefreshLocationBtn:(UIButton *)sender{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [_locService startUserLocationService];
    });
}

-(void)getFirstPageData{
    _offset = 0;
    [self refreshData];
}

-(void)refreshData{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self getMerchantList];
    });
}

-(void)loadMoreData{
    NSLog(@"2222  offset:%zd",_offset);
    _offset = _offset + 10;
    NSLog(@"3333  offset:%zd",_offset);
    [self refreshData];
}


//获取商家列表
-(void)getMerchantList{
    //    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    
    
    
    
    NSInteger page1=_offset/10;
    //获取指定类型的商铺(name=商铺类型名，传全部类型可以查出全部&page=0&area=贵阳市内区域名，不传可以得到全部区域的内容)
    NSString *url=[zhidingcategoryshop stringByAppendingFormat:@"&name=%@&page=%ld&area=%@",self.shoptype,(long)page1,self.shoparea];
    //    NSString *url=@"http://www.hltgz.com/wx/mobile/index.php?m=default&c=appinterface&a=recommend&page=0";
    [HLTNetWorkingtool getyouhuilist:url success:^(NSMutableArray *ary) {
        
        
        if (_offset<10) {
            [_recommendArray removeAllObjects];
        }
        
        
        for (int i = 0; i < ary.count; i++) {
            RecommendModel *recommend = [RecommendModel objectWithKeyValues:ary[i]];
            [_recommendArray addObject:recommend];
        }
        
        [self.tableView reloadData];
        //刷新指定的section,显示推荐商铺的部分
        //        NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:0];
        //        [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView.header endRefreshing];
        [self.tableView.footer endRefreshing];
    } faliure:^(NSString *error) {
        
        [self.tableView.header endRefreshing];
        [self.tableView.footer endRefreshing];
        
        
    }];
    
    
    
    
    
}




//获取cate分组信息
-(void)getCateListData{
    //    NSString *urlStr = @"http://api.meituan.com/group/v1/poi/cates/showlist?__skck=40aaaf01c2fc4801b9c059efcd7aa146&__skcy=hSjSxtGbfd1QtKRMWnoFV4GB8jU%3D&__skno=0DEF926E-FB94-43B8-819E-DD510241BCC3&__skts=1436504818.875030&__skua=bd6b6e8eadfad15571a15c3b9ef9199a&__vhost=api.mobile.meituan.com&ci=1&cityId=1&client=iphone&movieBundleVersion=100&msid=48E2B810-805D-4821-9CDD-D5C9E01BC98A2015-07-10-12-44726&userid=10086&utm_campaign=AgroupBgroupD100Fa20141120nanning__m1__leftflow___ab_pindaochangsha__a__leftflow___ab_gxtest__gd__leftflow___ab_gxhceshi__nostrategy__leftflow___ab_i550poi_ktv__d__j___ab_chunceshishuju__a__a___ab_gxh_82__nostrategy__leftflow___ab_i_group_5_3_poidetaildeallist__a__b___b1junglehomepagecatesort__b__leftflow___ab_gxhceshi0202__b__a___ab_pindaoquxincelue0630__b__b1___ab_i550poi_xxyl__b__leftflow___ab_i_group_5_6_searchkuang__a__leftflow___i_group_5_2_deallist_poitype__d__d___ab_pindaoshenyang__a__leftflow___ab_b_food_57_purepoilist_extinfo__a__a___ab_waimaiwending__a__a___ab_waimaizhanshi__b__b1___ab_i550poi_lr__d__leftflow___ab_i_group_5_5_onsite__b__b___ab_xinkeceshi__b__leftflowGmerchant&utm_content=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&utm_medium=iphone&utm_source=AppStore&utm_term=5.7&uuid=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&version_name=5.7";
    
    //    [[NetworkSingleton sharedManager] getCateListResult:nil url:urlStr successBlock:^(id responseBody){
    //        NSLog(@"获取cate分组信息成功");
    //    } failureBlock:^(NSString *error){
    //        NSLog(@"获取cate分组信息失败:%@",error);
    //    }];
}



#pragma mark - UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _recommendArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 32;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screen_width, 30)];
    headerView.backgroundColor = RGB(240, 239, 237);
    
    //
    UILabel *locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, screen_width-10-40, 30)];
    locationLabel.font = [UIFont systemFontOfSize:13];
    //    locationLabel.text = @"当前：海淀区中关村大街";
    locationLabel.text = [NSString stringWithFormat:@"当前位置：%@",_locationInfoStr];
    locationLabel.textColor = [UIColor lightGrayColor];
    [headerView addSubview:locationLabel];
    
    //
    UIButton *refreshBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    refreshBtn.frame = CGRectMake(screen_width-30, 5, 20, 20);
    [refreshBtn setImage:[UIImage imageNamed:@"icon_dellist_locate_refresh"] forState:UIControlStateNormal];
    [refreshBtn addTarget:self action:@selector(OnRefreshLocationBtn:) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:refreshBtn];
    return headerView;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    static NSString *cellIndentifier = @"recommendcell";
    RecommendCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    if (cell == nil) {
        cell = [[RecommendCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
    }
    
    RecommendModel *recommend = _recommendArray[indexPath.row];
    [cell setRecommendData:recommend];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
    
    
}



#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    RecommendModel *recommend = _recommendArray[indexPath.row-1];
    //                    [recommend objectArray2keyValuesArray]
    //                    NSString *shopId = recommend.Shop_id;
    //            NSLog(@"shop id:%@",shopId);
    
    HLTShopViewController *shopvc=[[HLTShopViewController alloc]init];
    shopvc.shopcontent=recommend;
    //隐藏tabbar
    shopvc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:shopvc animated:YES];
    //                    HLTShopcontentViewController *shopVC = [[HLTShopcontentViewController alloc] init];
    //                    shopVC.imagearray=imagearray;
    //                    shopVC.shopID = shopId;
    //                    shopVC.shopcontent=recommend;
    //                    [self.navigationController pushViewController:shopVC animated:YES];
    
    
    
    
    
    
    
}





#pragma mark - UIGestureRecognizerDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    //    NSLog(@"touch view  1:%@",touch.view);
    //    NSLog(@"touch view  11:%@",touch.view.superview);
    //    NSLog(@"touch view  111:%@",touch.view.superview.superview);
    if ([touch.view isKindOfClass:[UITableView class]]) {
        //        NSLog(@"111111");
        return NO;
    }
    if ([touch.view.superview isKindOfClass:[UITableView class]]) {
        //        NSLog(@"22222");
        return NO;
    }
    if ([touch.view.superview.superview isKindOfClass:[UITableView class]]) {
        //        NSLog(@"33333");
        return NO;
    }
    if ([touch.view.superview.superview.superview isKindOfClass:[UITableView class]]) {
        //        NSLog(@"44444");
        return NO;
    }
    return YES;
}



#pragma mark - JZMerchantFilterDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath withId:(NSNumber *)ID withName:(NSString *)name{
    NSLog(@"ID:%@  name:%@",ID,name);
    _KindID = [ID integerValue];
    
    _maskView.hidden = YES;
    [self getFirstPageData];
}

//动画-由大变小
-(void)zoomOut:(UIView *)view andAnimationDuration:(float)duration andWait:(BOOL)wait{
    __block BOOL done = wait;
    view.transform = CGAffineTransformIdentity;
    [UIView animateWithDuration:duration animations:^{
        view.transform = CGAffineTransformMakeScale(0, 0);
    } completion:^(BOOL finished){
        done = YES;
    }];
    
    while (done == NO) {
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
    }
}

//动画-由小变大
-(void)zoomIn:(UIView *)view andAnimationDuration:(float)duration andWait:(BOOL)wait{
    __block BOOL done = wait;
    //    view.transform = CGAffineTransformIdentity;
    view.transform = CGAffineTransformMakeScale(0, 0);
    [UIView animateWithDuration:duration animations:^{
        //        view.transform = CGAffineTransformMakeScale(0, 0);
        view.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished){
        done = YES;
    }];
    
    while (done == NO) {
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
    }
}





@end
